package at.sysarch.filter;

import java.util.Collections;
import java.util.LinkedList;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.model.Line;
import at.sysarch.util.LineComparator;

public class SortShiftsFilter extends DataEnrichmentFilter<LinkedList<Line>, LinkedList<Line>> {
	
	private LineComparator _comparator;
	
	public SortShiftsFilter() {
		
		_comparator = new LineComparator();
	}
	
	/**
	 * Sorts the incoming lines in ascending order.
	 * Result is one single list containing all the lines in order.
	 */
	@Override
	protected boolean fillEntity(LinkedList<Line> nextVal, LinkedList<Line> entity) {

		if (nextVal.size() == 0) {
			
			return false;
		} else {
			
			for (Line l: nextVal) {
				
				entity.add(l);
			}
			Collections.sort(entity, _comparator);
			return false;
		}
	}

	@Override
	protected LinkedList<Line> getNewEntityObject() {

		return new LinkedList<Line>();
	}

}
